package com.thenmoret.admin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.thenmoret.pojo.Article;
import com.thenmoret.pojo.Type;
import com.thenmoret.service.ArticleService;
import com.thenmoret.service.TypeService;

@RequestMapping("/admin")
@Controller
public class ArticleAdminSkipController {

	@Autowired
	private TypeService typeService;
	@Autowired
	private ArticleService articleService;
	/**
	 * 跳转到添加界面
	 * @return
	 */
	@RequestMapping("/saveUI")
	public ModelAndView ArticleAddUI()
	{
		ModelAndView mav = new ModelAndView("/admin/ArticleAdd");
		
		//获取文章类型的集合
		List<Type> listType = typeService.findAll();
		mav.addObject("ArticleType", listType);
		return mav;
	}
	
	/**
	 * 跳转到文章管理
	 * @return
	 */
	@RequestMapping("/listUI")
	public String ArticleListUI()
	{
		return "/admin/ArticleManager";
	}
	
	/*
	 * 跳转到文章编辑界面
	 */
	@RequestMapping("/editorUI")
	public ModelAndView ArticleEditorUI(@RequestParam("articleId") Integer id)
	{
		ModelAndView mav = new ModelAndView("/admin/modifyArticle");
		Article article = articleService.findArticleById(id);
		List<Type> listType = typeService.findAll();
		mav.addObject("ArticleType", listType);
		mav.addObject("article", article);
		return mav;
	}
	
	
	
}
